home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_plotutils.idb / usr / freeware / share / ode / coupled.ode.z / coupled.ode
Encoding:
Text File  |  1998-10-28  |  864 b   |  40 lines

  1. # This example simulates two similar pendulums, coupled with a horizontal
  2. # spring.  The motion is taken to be undamped.
  3. # The plot shows the displacement of one of the pendulums, as a function of
  4. # time.  It illustrates how energy (e.g. maximum displacement) oscillates
  5. # back and forth between the two.
  6.  
  7. # You may run this example by doing:
  8. #
  9. #    ode < coupled.ode | graph -T X -C
  10. # or alternatively, to get a real-time plot,
  11. #
  12. #    ode < coupled.ode | graph -T X -C -x 0 50 -y -0.6 0.6
  13.  
  14. # The equations are:
  15. # m*x1'' = - m*g*x1/l + k(x2 - x1)
  16. # m*x2'' = - m*g*x2/l - k(x2 - x1)
  17.  
  18. xone' = vxone
  19. xtwo' = vxtwo
  20.  
  21. vxone' = -g*xone/lone + k/mone * ( xtwo - xone)
  22. vxtwo' = -g*xtwo/ltwo - k/ltwo * ( xtwo - xone)
  23.  
  24. k = 1
  25. g = 9.8        # acceleration due to gravity
  26. lone = 5
  27. ltwo = 5
  28. mone = 1
  29. mtwo = 1
  30.  
  31. xone = 0.0
  32. xtwo = 0.3
  33. vxone = 0
  34. vxtwo = 0
  35.  
  36. print t, xone
  37. step 0,50
  38.